package update;

import java.util.Arrays;

import protocol.CtfActionException;
import utils.Conversions;

/**
 * Represents the cell (and player position) update.
 */
public class CellUpdatePacket {
	int numCellUpdates;
	byte[] cellUpdatesInBytes;
	
	public int getNumCellUpdates() { return numCellUpdates; }
	public byte[] getCellUpdatesInBytes() { return cellUpdatesInBytes; }
	
	public CellUpdatePacket( byte[] response ) throws CtfActionException {
		byte[] headerInBytes = Arrays.copyOfRange(response, 0, 4);
		byte[] bodyInBytes 	 = Arrays.copyOfRange(response, 4, response.length);
		
		if ( bodyInBytes.length == 0 ) return;
			
		this.numCellUpdates = Conversions.bytesToInt4(headerInBytes);
		this.cellUpdatesInBytes = bodyInBytes;
	}
}

